package com.designed.pattern.addition.strategyfactoryDecorate;

/**
 * @author yifei
 * @description
 * @date 2024/1/2
 **/
public class CashReturn extends CashSuper {

    private double moneyCondition = 0d;     // 返利条件
    private double moneyReturn = 0d;    // 返利值

    public CashReturn(double moneyCondition, double moneyReturn) {
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    public double acceptCash(double price, int num) {
        double result = price * num;
        if (moneyCondition > 0 && result >= moneyCondition) {
            result = result - Math.floor(result / moneyCondition) * moneyReturn;
        }
        return component != null ? super.acceptCash(result, 1) : result;
    }
}
